import Vue from 'vue'

export const USER_LOGIN = 'USER_LOGIN'
export const USER_LOGOUT = 'USER_LOGOUT'

const localStorage = window.localStorage

export default {
  state: localStorage.getItem('token'),
  mutations: {
    [USER_LOGIN] (state, token) {
      //localStorage.setItem('token', token)
      state = token
    },
    [USER_LOGOUT] (state) {
      localStorage.removeItem('token')
      Vue.delete(state, state)
    }
  },
  actions: {
    [USER_LOGIN] ({commit}, token) {
      commit(USER_LOGIN, token)
    },
    [USER_LOGOUT] ({commit}) {
      commit(USER_LOGOUT)
    }
  }
}
